package com.seanliao.nav.security;

import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 自定义用户信息 (springboot com.seanliao.nav.security)
 */
public class MyUserDetails implements UserDetails {

    private final String username;
    private final String password;
    private final boolean isBan;

    @Getter
    private final Long userId;

    @Getter
    @Setter
    private String nickname;
    @Getter
    @Setter
    private List<String> permissions;
    @Getter
    @Setter
    private Map<String, String> roles;
    @Getter
    @Setter
    private Map<String, String> availableRoles;

    public MyUserDetails(Long userId, String username, String password, boolean isBan) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.isBan = isBan;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return !isBan;
    }


}
